package med;

import dbTools.DBTools;
import medM.MedMessageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * Servlet implementation class MedInnerDeleteServlet
 */
@WebServlet("/MedInnerDeleteServlet")
public class MedInnerDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MedInnerDeleteServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=GBK");
		request.setCharacterEncoding("GBK");
		response.setCharacterEncoding("GBK");
		String s=new String(request.getParameter("s").getBytes("ISO-8859-1"),"GBK");
		String[] ss=s.split(",");
		String classification=ss[0];
		String typeName=ss[1];
		String id=ss[2];
		DBTools db=new DBTools();
		db.open();
		String sqlU="UPDATE medInfo SET classification=NULL WHERE id="+id;
		db.update(sqlU);
		String sql="SELECT * FROM medInfo WHERE classification="+classification;
		ResultSet rs=db.select(sql);
		ArrayList al=new ArrayList();
		try {
			while(rs.next()){
				MedMessageBean mmb=new MedMessageBean(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10),rs.getString(11),rs.getString(12),rs.getString(13),rs.getString(14),rs.getString(15),rs.getInt(16),rs.getString(17),rs.getString(18),rs.getString(19),rs.getString(20),rs.getString(21),rs.getString(22),rs.getString(23),rs.getString(24),rs.getString(25));
				al.add(mmb);
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String sql1="SELECT * FROM medInfo";
		ResultSet rs1=db.select(sql1);
		ArrayList al1=new ArrayList();
		try {
			while(rs1.next()){
				MedMessageBean mmb=new MedMessageBean(rs1.getInt(1),rs1.getString(2),rs1.getString(3),rs1.getString(4),rs1.getString(5),rs1.getString(6),rs1.getString(7),rs1.getString(8),rs1.getString(9),rs1.getString(10),rs1.getString(11),rs1.getString(12),rs1.getString(13),rs1.getString(14),rs1.getString(15),rs1.getInt(16),rs1.getString(17),rs1.getString(18),rs1.getString(19),rs1.getString(20),rs1.getString(21),rs1.getString(22),rs1.getString(23),rs1.getString(24),rs1.getString(25));
				al1.add(mmb);
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		db.close();
		request.setAttribute("Typeid", classification);
		request.setAttribute("TypeName", typeName);
		request.setAttribute("al", al);
		request.setAttribute("al1", al1);
		request.getRequestDispatcher("/MedInnerMessage.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
